package com.doubi.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

@ApiModel(value = "统一返回对象")
public class AppUiModel<T> implements Serializable {
    @ApiModelProperty(value = "识别码", name = "code", example = "200为成功 400错误  401未登陆")
    private int code;
    @ApiModelProperty(value = "回应消息", name = "msg", example = "回应消息")
    private String msg;
    @ApiModelProperty(value = "数据", name = "data", example = "数据")
    private T data;

    //200 成功 400 错误 401需要登录
    public AppUiModel(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public AppUiModel(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public AppUiModel(T data) {
        this.code = 200;
        this.msg = "操作成功";
        this.data = data;
    }

    public AppUiModel(int code) {
        this.code = code;
        if (code == 200) {
            this.msg = "操作成功！";
        } else if (code == 401) {
            this.msg = "请先登录！";
        } else {
            this.msg = "操作失败！";
        }
    }

    public AppUiModel() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
